/**   
* @Title: DaiHouYwView.java 
* @Package com.zjdiepu.www.manage.api.zpp.view 
* 
* @author zhangpp
* @date 2017年6月1日 上午11:30:13 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.view;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.dh.IDhInsteadPaymentService;
import com.zjdiepu.www.ibiz.dh.IDhOverdueListService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessCarService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessLoanService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.model.dh.dto.DhInsteadPayment;
import com.zjdiepu.www.model.dh.dto.DhOverdueList;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;
import com.zjdiepu.www.util.ExceptionHelper;

/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：DaiHouYwView   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年6月1日 上午11:30:13   
 * 修改人：zhangpp
 * 修改时间：2017年6月1日 上午11:30:13   
 * 修改备注：   
 * @version V1.0     
 */
@Controller
@RequestMapping(value= "DaiHouYwView", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class DaiHouYwView {

	@Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
	@Resource
    private ICachedDictionaryService cachedDictionaryService;
	@Resource
	private IYwBusinessCarService ywBusinessCarService; 
	@Resource
	private IYwBusinessLoanService ywBusinessLoanService;
	@Resource
	private IDhOverdueListService dhOverdueListService;
	@Resource
	private PublicService publicService;
	@Resource
	private IDhInsteadPaymentService dhInsteadPaymentService;
	
	/**
	* 贷后业务/客户申请退押金表
	* @author zhangpp
	* @Title: getBankFangKuanListView 
	* 
	* @param @param model
	* @param @param id
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "贷后业务/客户申请退押金表", response = Boolean.class, httpMethod="GET", tags={"贷后业务/客户申请退押金表"})
    @RequestMapping(value = "daiHouYwKeHuShenTuiYaJinList", method = RequestMethod.GET)
    public String daiHouYwKeHuShenTuiYaJinList(Model model,String busiId) {
		if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getBusiId());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
		
		model.addAttribute("busiId", busiId);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		
		
		//查询额外的值
		YwBusinessCar ywBusinessCar = new YwBusinessCar();
		ywBusinessCar.setBusiId(busiId);
		ywBusinessCar.setDpStatus(1);
		ywBusinessCar = ywBusinessCarService.selectRefined(ywBusinessCar);
		if(null != ywBusinessCar)
		{
			ywBusinessCar.setCarType(publicService.getDictionaryName(ywBusinessCar.getCarType(), DataDicType.CAR_TYPE.getCode()));
		}
		model.addAttribute("ywBusinessCar", ywBusinessCar);
		
		YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
		ywBusinessLoan.setBusiId(busiId);
		ywBusinessLoan.setDpStatus(1);
		ywBusinessLoan = ywBusinessLoanService.selectRefined(ywBusinessLoan);
		if(null != ywBusinessLoan)
		{
			ywBusinessLoan.setLoanType(publicService.getDictionaryName(ywBusinessLoan.getLoanType(), DataDicType.LOAN_TYPE.getCode()));
			ywBusinessLoan.setLoanBankDisplay(cachedDictionaryService.getName(ywBusinessLoan.getLoanBank(), DataDicType.LOAN_BANK));
			ywBusinessLoan.setLoanTypeDisplay(ywBusinessLoan.getLoanType());
		}
		model.addAttribute("ywBusinessLoan", ywBusinessLoan);
		
		DhOverdueList dhOverdueList = new DhOverdueList();
		dhOverdueList.setBusiId(busiId);
		dhOverdueList.setDpStatus(1);
		dhOverdueList = dhOverdueListService.selectRefined(dhOverdueList);
		model.addAttribute("dhOverdueList", dhOverdueList);
		
		DhInsteadPayment dhInsteadPayment = new DhInsteadPayment();
		dhInsteadPayment.setBusiId(busiId);
		dhInsteadPayment.setStatusInstead(30);
		dhInsteadPayment.setDpStatus(1);
		dhInsteadPayment = dhInsteadPaymentService.selectRefined(dhInsteadPayment);
		model.addAttribute("dhInsteadPayment", dhInsteadPayment);
		
    	return "daiHouYw/refundDeposit";
    }
}
